package com.ihunanren.biz.weixin.manager.impl;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables;
import com.ihunanren.biz.common.HnrResourceLoader;
import com.ihunanren.biz.weixin.domain.school.Country;
import com.ihunanren.biz.weixin.manager.IDivisionManager;

public class DivisionManager implements IDivisionManager{

	private Country country = null;

	public void init() throws Exception {
		byte [] josnArray = HnrResourceLoader.getResoureceAsByteArray("wx_division_university.dat");
		country = JSON.parseObject(josnArray, Country.class);
	}

	@Override
	public Country getCuntry() {
		if (country == null) {
			try {
				init();
			} catch (Exception e) {
				Throwables.propagate(e);
			}
		}
		return country;
	}

	public static void main(String[] args) {
		DivisionManager divisionManager = new DivisionManager();
		try {
			divisionManager.init();
			Country country = divisionManager.getCuntry();
			System.out.println(ToStringBuilder.reflectionToString(country));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
